@extends('user.base')
@section('title', '题库中心')
@section('content')
        <div class="layui-col-md10" style="padding: 0 0 0 15px">
            <div class="layui-row layui-col-space15"  id="selectsub" >
                <div class="layui-col-md12">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-xs12 layui-col-md12">
                            <div class="layui-card dhbwl-count-card">
                                <div class="layui-card-header">
                                    <span class="layui-badge dhbwl-bg-blue">请先选择科目分类</span>
                                    <a id="btnFoldAll"  style="margin-left: 15px;float: right" href="javascript:;"><span class="layui-badge dhbwl-bg-blue">全部折叠</span></a>
                                    <a id="btnExpandAll" style="margin-left: 15px;float: right" href="javascript:;"><span class="layui-badge dhbwl-bg-blue">全部展开</span></a>
                                </div>
                                <div class="layui-card-body">
                                    <table id="subject"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@include('user._footer')
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/user.js"></script>
<script src="/static/js/layui/layui.all.js"></script>
    <script>
        layui.config({
            base: '/static/js/'
        }).use(['element', 'treeTable'], function () {
            var element = layui.element;
            var treeTable = layui.treeTable;
            @if (session('verified'))
            layer.msg('邮箱验证已经通过');
                @endif
            var insTb = treeTable.render({
                elem: '#subject',
                url: '{{route('api.subjects.list')}}',
                text: {
                    none: '<div style="padding: 18px 0;">无科目信息，请联系管理员添加~</div>'
                },
                tree: {
                    iconIndex: 1,
                    isPidData: true,
                    treeSpid: 0,
                    idName: 'id',  // id字段名称
                    pidName: 'parent_id',
                },
                cols: [[
                    {type: 'numbers'},
                    {field: 'name', width: 540, title: '科目名称'},
                    {
                        align: 'center', title: '操作', templet: function (d) {
                            if (d.parent_id) {
                                return '<a onclick="select(\'' + d.id + '\',\'' + d.name + '\',\'{{route('user.subject.update')}}\',\'{{csrf_token()}}\')" class="layui-btn dhbwl-bg-blue layui-btn-xs" >去练习</a>';

                            }
                        }
                    }
                ]]
            });
            $('#btnExpandAll').click(function () {
                insTb.expandAll();
            });
            $('#btnFoldAll').click(function () {
                insTb.foldAll();
            });
            //知识点 表格
        });
    </script>
@endsection
